// License Notification
//======================================================
// Copyright (c) 2010 Channel Intelligence Inc.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// ======================================================




using System;
using System.Reflection;

namespace CIP4.Item
{
    [AttributeUsage(AttributeTargets.Property)]
    public class CIP4ExternalIDAttribute : Attribute
    {
        public int Rank { get; set; }

        public static CIP4ExternalIDAttribute GetAttribute(PropertyInfo property)
        {
            object[] attributes = property.GetCustomAttributes (typeof (CIP4ExternalIDAttribute), false);
            switch (attributes.Length)
            {
                case 0:
                    return null;

                case 1:
                    return (CIP4ExternalIDAttribute)attributes[0];
            }
            return null;
        }

        public CIP4ExternalIDAttribute() { }

        public CIP4ExternalIDAttribute(int rank) 
        {
            if (rank < 0)
            {
                throw new ArgumentException (string.Format ("Rank {0} is not valid: must be a non-negative integer.", rank));
            }
            Rank = rank; 
        }
    }

    [AttributeUsage(AttributeTargets.Property)]
    public class CIP4ModifiedDateAttribute : Attribute
    {
        public static CIP4ModifiedDateAttribute GetAttribute(PropertyInfo property)
        {
            object[] attributes = property.GetCustomAttributes(typeof(CIP4ModifiedDateAttribute), false);
            switch (attributes.Length)
            {
                case 0:
                    return null;

                case 1:
                    return (CIP4ModifiedDateAttribute)attributes[0];

                default:
                    throw new ApplicationException ("Property has more than one CIP4ModifiedDate attribute attached to it.");
            }
        }
    }

    [AttributeUsage(AttributeTargets.Property)]
    public class CIP4EnteredDateIDAttribute : Attribute
    {
        public static CIP4EnteredDateIDAttribute GetAttribute(PropertyInfo property)
        {
            object[] attributes = property.GetCustomAttributes(typeof(CIP4EnteredDateIDAttribute), false);
            switch (attributes.Length)
            {
                case 0:
                    return null;

                case 1:
                    return (CIP4EnteredDateIDAttribute)attributes[0];

                default:
                    throw new ApplicationException ("Property has more than one CIP4EnteredDateID attribute attached to it.");
            }
        }

    }
}
